from typing import List
from langchain_community.graphs.graph_document import GraphDocument

def update_node_ids(graph_documents: List[GraphDocument]) -> List[GraphDocument]:
    """
    Update node IDs for relationships with the HASDETAIL_ prefix in a list of GraphDocument objects.

    Args:
        graph_documents (List[GraphDocument]): List of GraphDocument objects.

    Returns:
        List[GraphDocument]: List of updated GraphDocument objects.
    """
    for graph_document in graph_documents:
        print("Updating node IDs for graph document...")

        relationships = graph_document.relationships

        # Update relationship target IDs to be hierarchical for relationships with 'HASDETAIL_' prefix
        for rel in relationships:
            if rel.type.startswith('HASDETAIL_'):
                source_id = rel.source.id
                target_id = rel.target.id
                if not target_id.startswith(f"{source_id}_"):
                    rel.target.id = f"{source_id}_{target_id}"

    return graph_documents
